import { createRouter, createWebHistory } from 'vue-router'
// import HomeView from '../views/HomeView.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/index',
      name: 'index',
      component: () => import('../views/Index.vue'),
      children: [
        // 首页
        {
          path: '/index/home',
          name: 'home',
          meta: { title: '首页' },
          component: () => import('../views/Index/Home.vue'),
        },
        // 家校互动
        {
          path: '/index/family-schoolInteraction',
          name: 'family-schoolInteraction',
          meta: { title: '家校互动' },
          component: () => import('../views/Index/Family-schoolInteraction.vue'),

          children: [
            // 通知列表
            {
              path: '/index/family-schoolInteraction/alertlist',
              name: 'alertlist',
              meta: { title: '通知列表' },
              component: () => import('../views/Index/Family-schoolInteraction/AlertList.vue'),
            },
            // 通知类型管理列表
            {
              path: '/index/family-schoolInteraction/alerttype',
              name: 'alerttype',
              meta: { title: '通知类型管理' },
              component: () => import('../views/Index/Family-schoolInteraction/AlertType.vue'),
            },
            // 评价列表
            {
              path: '/index/family-schoolInteraction/evaluatelist',
              name: 'evaluatelist',
              meta: { title: '评价列表' },
              component: () => import('../views/Index/Family-schoolInteraction/Evaluatelist.vue'),
            },
            // 评价权限设置
            {
              path: '/index/family-schoolInteraction/evaluateset',
              name: 'evaluateset',
              meta: { title: '评价权限设置' },
              component: () => import('../views/Index/Family-schoolInteraction/Evaluateset.vue'),
            },
            {
              path: '/index/family-schoolInteraction',
              redirect: '/index/family-schoolInteraction/alertlist'
            },
            // 出勤统计
            {
              path: '/index/family-schoolInteraction/duty',
              name: 'duty',
              meta: { title: '出勤统计' },
              component: () => import('../views/Index/Family-sschoolInteraction/Duty.vue'),
            },
            {
              path: '/index/family-schoolInteraction/dutytotal',
              name: 'dutytotal',
              component: () => import('../views/Index/Family-sschoolInteraction/Dutytotal.vue'),
            },
            //设备报修
            {
              path: '/index/family-schoolInteraction/repair',
              name: 'repair',
              meta: { title: '设备报修' },
              component: () => import('../views/Index/Family-sschoolInteraction/Repair.vue'),
            },
            {
              path: '/index/family-schoolInteraction/repairadd',
              name: 'repairadd',
              meta: { title: '新增设备报修' },
              component: () => import('../views/Index/Family-sschoolInteraction/Repairadd.vue'),
            },
            {//相册
              path: '/index/family-schoolInteraction/imglist',
              name: 'imglist',
              meta: { title: '相册' },
              component: () => import('../views/Index/Family-schoollnteraction-ljy/Imglist.vue'),
            },
            {//相册审核列表
              path: '/index/family-schoolInteraction/audit_list',
              name: 'audit_list',
              meta: { title: '相册审核列表' },
              component: () => import('../views/Index/Family-schoollnteraction-ljy/Audit List.vue'),
            },
            {//相册审核设置
              path: '/index/family-schoolInteraction/audit_set',
              name: 'audit_set',
              meta: { title: '相册审核设置' },
              component: () => import('../views/Index/Family-schoollnteraction-ljy/Audit Settings.vue'),
            },
            {//投票
              path: '/index/family-schoolInteraction/vote',
              name: 'vote',
              meta: { title: '投票' },
              component: () => import('../views/Index/Family-schoollnteraction-ljy/Vote.vue'),
            },
            // 和VueRouter3相比 404路由的写法有变化,包括嵌套路由的 404路由.
            {
              // path: new RegExp('/:id*'),
              // path:'*',
              // path:'/:id*',
              path: '/index/family-schoolInteraction:id(.*)',
              component: () => import('../views/NotFound.vue')
            },
            // 学生请假列表
            {
              path: '/index/family-schoolInteraction/StudentLeaveList',
              name: 'StudentLeaveList',
              meta: { title: '学生请假列表' },
              component: () => import('../views/Index/Family-schoolInteraction/Student Leave List.vue'),
            },
            // 学生请假审核列表
            {
              path: '/index/family-schoolInteraction/Studentleavereview',
              name: 'Studentleavereview',
              meta: { title: '学生请假审核' },
              component: () => import('../views/Index/Family-schoolInteraction/Student leave review.vue'),
            },
            // 学生请假审核表单查看
            {
              path: '/index/family-schoolInteraction/reviewchecklist',
              name: 'reviewchecklist',
              component: () => import('../views/Index/Family-schoolInteraction/reviewchecklist.vue'),
            },
            // 请假记录
            {
              path: '/index/family-schoolInteraction/LeaveRecord',
              name: 'LeaveRecord',
              meta: { title: '请假记录' },
              component: () => import('../views/Index/Family-schoolInteraction/Leave Record.vue'),
            },
            // 请假设置
            {
              path: '/index/family-schoolInteraction/LeaveSettings',
              name: 'LeaveSettings',
              meta: { title: '请假设置' },
              component: () => import('../views/Index/Family-schoolInteraction/Leave Settings.vue'),
            },
            // 学生请假申请表单填写
            {
              path: '/index/family-schoolInteraction/StudentLeaveListform',
              name: 'Listfrom',
              meta: { title: '学生请假申请表' },
              component: () => import('../views/Index/Family-schoolInteraction/List from.vue'),
            },
            // 学生请假申请表单查看
            {
              path: '/index/family-schoolInteraction/LeaveListformcheck',
              name: 'Listfromcheck',
              meta: { title: '学生请假申请表单查看' },
              component: () => import('../views/Index/Family-schoolInteraction/check list.vue'),
            },
            // 健康中心列表
            {
              path: '/index/family-schoolInteraction/healthcenter',
              name: 'healthcenter',
              meta: { title: '健康中心' },
              component: () => import('../views/Index/Family-schoolInteraction/health center.vue'),
            },
            // 健康中心列表-发送提醒
            {
              path: '/index/family-schoolInteraction/healthremind',
              name: 'healthremind',
              meta: { title: '健康中心-发送提醒' },
              component: () => import('../views/Index/Family-schoolInteraction/health remind.vue'),
            },

          ]
        },
        {
          path: '/index/inform',
          name: 'inform',
          meta: { title: '局校通知' },
          component: () => import('../views/Index/Inform.vue'),
        },
        //消息统计
        {
          path: '/index/messageStatistics',
          name: 'messageStatistics',
          component: () => import('../views/Index/MessageStatistics.vue'),
          children: [
            //消息发布列表
            {
              path: '/index/messageStatistics/message_list',
              name: 'message_list',
              meta: { title: '消息发布' },
              component: () => import('../views/Index/MessageStatistics/Message_list.vue')
            },
            //消息发布概况
            {
              path: '/index/messageStatistics/messaging_overview',
              name: 'messaging_overview',
              meta: { title: '消息发布概况' },
              component: () => import('../views/Index/MessageStatistics/Messaging_Overview.vue')
            },
            //学校月发布列表
            {
              path: '/index/messageStatistics/school_ranking',
              name: 'school_Ranking',
              meta: { title: '学校月发布' },
              component: () => import('../views/Index/MessageStatistics/School_Ranking.vue')
            },
            //老师月发布列表
            {
              path: '/index/messageStatistics/teacher_ranking',
              name: 'teacher_ranking',
              meta: { title: '老师月发布 ' },
              component: () => import('../views/Index/MessageStatistics/Teacher_Ranking.vue')
            },
            //三级路由重定向
            {
              path: '/index/messageStatistics',
              redirect: '/index/messageStatistics/messaging_overview'
            },
            // 404路由
            // {
            //   path:'/:error(.*)',
            //   component:()=>import(''),
            // }
          ]
        },
        // 学校管理
        {
          path: '/index/schoolManagement',
          name: 'schoolManagement',
          meta: { title: '学校管理' },
          component: () => import('../views/Index/SchoolManagement.vue'),
          children: [
            //用户概况
            {
              path: '/index/schoolManagement/schoolOverview',
              name: 'schoolOverview',
              meta: { title: '用户概况' },
              component: () =>import('../views/Index/SchoolManagement/SchoolOverview.vue')
            },
            //三级路由重定向
            {
              path: '/index/schoolManagement',
              redirect: '/index/schoolManagement/schoolOverview',
            }
          ]
        },
        // 用户统计
        {
          path: '/index/userStatistics',
          name: 'userStatistics',
          meta: { title: '用户统计' },
          component: () => import('../views/Index/UserStatistics.vue'),
          children: [
            // 家长列表
            {
              path: '/index/userStatistics/listparents',
              name: 'listparents',
              meta: { title: '家长列表' },
              component: () => import('../views/Index/UserStatistics/Listparents.vue')
            },
            // 学生列表
            {
              path: '/index/userStatistics/studenslist',
              name: 'studenslist',
              meta: { title: '学生列表' },
              component: () => import('../views/Index/UserStatistics/StudentsList.vue')
            },
            // 老师列表
            {
              path: '/index/userStatistics/teacherlist',
              name: 'teacherlist',
              meta: { title: '老师列表' },
              component: () => import('../views/Index/UserStatistics/TeacherList.vue')
            },
            // 用户概况
            {
              path: '/index/userStatistics/userprofile',
              name: 'userprofile',
              meta: { title: '用户概况' },
              component: () => import('../views/Index/UserStatistics/UserProfile.vue')
            },
            //三级路由重定向
            {
              path: '/index/userStatistics',
              redirect: '/index/userStatistics/userprofile'
            }
          ]
        },
        // 路由重定向
        {
          path: '/index',
          redirect: '/index/home'
        },
        // 404
        {

          path: '/index/:id*',
          meta: { title: '404' },
          component: () => import('../views/NotFound.vue')
        }
      ]

    },
    // 通知列表-发布通知
    {
      path: '/editelert',
      name: 'editAlert',
      meta: { title: '通知列表-发布通知' },
      component: () => import('../views/EditAlert.vue'),
    },
    // 通知类型列表-添加通知类型
    {
      path: '/editalerttype',
      name: 'editalerttype',
      meta: { title: '通知类型-添加类型' },
      component: () => import('../views/EditAlertType.vue'),
    },
    //局校通知-发布通知
    {
      path: '/publish',
      name: 'publish',
      meta: { title: '局校通知-发布通知' },
      component: () => import('../views/Publish.vue'),
    },
    // 局校通知详情页
    {
      path: '/details',
      name: 'details',
      meta: { title: '局校通知详情页' },
      component: () => import('../views/Details.vue')
    },
    // 登录
    {
      path: '/login',
      name: 'login',
      meta: { title: '登录' },
      component: () => import('../views/Login.vue'),
    },
    // 注册
    {
      path: '/register',
      name: 'register',
      meta: { title: '注册' },
      component: () => import('../views/Register.vue'),
    },
    {//我的相册
      path: '/myimglist',
      name: 'myimglist',
      meta: { title: '我的相册' },
      component: () => import('../views/Index/Family-schoollnteraction-ljy/Myimglist.vue'),
    },
    // 发布相册
    {
      path: '/releaseimg',
      name: 'releaseimg',
      meta: { title: '发布相册' },
      component: () => import('../views/Index/Family-schoollnteraction-ljy/Releaseimg.vue'),
    },
    // 重定向
    {
      path: '/',
      redirect: '/index/home'
    },
    // 404
    {
      path: '/:id(.*)',
      meta: { title: '404' },
      component: () => import('../views/NotFound.vue')
    }
  ]
})


//路由的全局前置守卫方法
router.beforeEach((to, from, next) => {
  //参数一: to 新的路由对象
  //参数二: from 旧的路由对象
  //参数三: next 路由控制方法, 调用该方法则允许路由跳转, 未调用该方法则不允许路由跳转

  //动态更新网页标题
  document.title = to.meta.title;

  if (to.path === '/register') next()
  if (to.path === '/login') next()//跳往 登录页
  const tokenStr = window.localStorage.getItem('token')
  if (!tokenStr && to.path !== '/login') return next('login')
  next()

})

export default router
